const 
	DIGITS : array[1..36] of char = ('0', '1', '2', '3', '4', '5', '6', '7', '8',
																	 '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
																	 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
																	 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');

function DecToP(p : longint; n : int64) : string;

var 
	current, count, step : int64; 
	dig : array[0..1010] of int64;  
	i : longint;
	
begin
	current := n;
	result := '';
	if n = 0 then result := '0';
	count := 0;
	while current > 0 do begin
		inc(count);
		dig[count] := current mod p;
		current := current div p;
	end;
	for i := count downto 1 do 
		result := result + digits[dig[i] + 1];
end;